//
//  HTGoodSourceCell.m
//  TruckDriver
//
//  Created by Ting Han on 2017/9/26.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTGoodSourceCell.h"
#import "UIImageView+WebCache.h"

@interface HTGoodSourceCell ()

@property (weak, nonatomic) IBOutlet UILabel *startLabel;
@property (weak, nonatomic) IBOutlet UILabel *destiLabel;
@property (weak, nonatomic) IBOutlet UIView *callNumView;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *driverLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *truckTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *truckGoodsLabel;
@property (weak, nonatomic) IBOutlet UILabel *amountLabel;

@end

@implementation HTGoodSourceCell

- (void)setSearchModel:(HTGoodSearchModel *)searchModel{
    _searchModel = searchModel;
    self.startLabel.text = searchModel.fromadd;
    self.destiLabel.text = searchModel.toadd;
    self.driverLabel.text = searchModel.drivername;
    NSString *time =  [HTUtils timeIntervalFromLastTime:searchModel.createtime];
    if (![time isEqualToString:@"刚刚"]) {
        time = [NSString stringWithFormat:@"%@前",time];
    }
    self.timeLabel.text = time;
    self.amountLabel.text = [NSString stringWithFormat:@"%@元",searchModel.pricers];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.picurl] placeholderImage:[UIImage imageNamed:@"bg_headsculpture"]options:SDWebImageRefreshCached];
    
    NSString *length = [HTUtils sortLengthDisplayStringWith:searchModel.heiht];
    NSString *type = @"不限车型";
    if (!(searchModel.type == nil || searchModel.type.length <= 0)) {
        type = searchModel.type;
    }
    NSString *dun = @"";
    if ([searchModel.utit isEqualToString:@"1"]) {
        dun =[NSString stringWithFormat:@"%@吨",searchModel.weight];
    }else{
        dun =[NSString stringWithFormat:@"%@方",searchModel.weight];
    }
    NSString *cartype = @"";
    if (!(searchModel.cartype == nil || searchModel.cartype.length <= 0)) {
        cartype = searchModel.cartype;
    }
    self.truckTypeLabel.text = [NSString stringWithFormat:@"%@ %@/%@ %@",length,type,cartype,dun];
    NSString *first = (searchModel.addtype == nil || searchModel.addtype.length <= 0)?@"":searchModel.addtype;
    NSString *second = (searchModel.strattime == nil || searchModel.strattime.length <= 0)? @"" :[NSString stringWithFormat:@"装车时间 %@",searchModel.strattime];
    NSString *last = (second.length > 0)?[NSString stringWithFormat:@"%@ %@",second,first]:first;
    self.truckGoodsLabel.text =  last;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didCallNumber:)];
    [self.callNumView addGestureRecognizer:tap];
    self.headImageView.userInteractionEnabled = YES; self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = kWidth(25);
}
- (void)didCallNumber:(id)sender{
    if (![HTMUserDefaultUtil isLogin]) {
        [HTShowUtil showMessage:@"您还未登录，请先登录"];
        return;
    }
    if (![self.isauitd isEqualToString:@"1"]) {
        [HTShowUtil showMessage:@"您还未认证成功，请先认证"];
        return;
    }
    NSString *phone = self.searchModel.phone;
    NSString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    [HTUtils netLoadCallRecordWithOrderid:self.searchModel.orderid];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}


@end
